security: remove .svg from load-html extension allowlist#1153
security: remove .svg from load-html extension allowlist#1153garagon wants to merge 1 commit intogarrytan:mainfrom
Conversation
SVG files can contain inline <script> tags, event handlers (onload, onclick), and <foreignObject> elements. When loaded via setContent(), JavaScript executes in an about:blank context with full fetch() access to localhost — including the gstack server itself. Attack vector: a malicious SVG placed in a project directory (via git clone, npm package, or download) gets loaded by the AI agent through load-html. The SVG's JavaScript modifies the DOM to inject prompt injection payloads that the agent reads on subsequent text/snapshot commands. SVG rendering is still available via `goto file://path/to/file.svg` which goes through validateNavigationUrl + validateReadPath with safe-dirs enforcement.
a18d3e6 to
3095f39
Compare
|
Rebased onto current Re-checked the threat in main while I was here: nothing in v1.13–v1.17 mitigates the |
Problem
load-htmlaccepts.svgfiles in its extension allowlist. SVG files can contain inline JavaScript that executes when loaded via Playwright'spage.setContent():What happens
.svglands in the project directory (via git clone, npm dependency, user download).load-html malicious.svg.setContent()renders the SVG in anabout:blankcontext. JavaScript executes.fetch()access tohttp://127.0.0.1:<port>— the gstack server itself. It can issue/commandrequests with the auth token (if discoverable) or modify the DOM to inject prompt injection payloads.textorsnapshoton the page and reads the injected content.SVG supports three JS execution vectors:
<script>blocks, event handler attributes (onload,onclick, etc.), and<foreignObject>embedding arbitrary HTML.Why this matters for the threat model
The gstack security stack (Confusion Protocol, hidden-element detection, ML classifier) defends against untrusted web content influencing the agent. But
load-htmltreats file content as trusted local HTML — it bypasses the Confusion Protocol for root tokens. A malicious SVG in a cloned repo gets the same trust level as the agent's own commands.Fix
Remove
.svgfromALLOWED_EXT. SVG rendering is still available throughgoto file://path/to/file.svg, which goes throughvalidateNavigationUrl+validateReadPathwith safe-dirs enforcement and loads in a properfile://origin (notabout:blank).Two lines changed in
write-commands.ts:.svgremoved from allowlistTest
New test case:
load-html rejects .svg files— writes a valid SVG to tmpdir, confirmsload-htmlthrows with "does not appear to be HTML."Test plan
bun test browse/test/commands.test.ts— 224/224 pass, 0 fail.svgrejection test passes.html/.htm/.xhtmltests still pass.txt) still passes